home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
ZSI
/
writer.pyo
(
.txt
)
< prev
Wrap
Python Compiled Bytecode
|
2008-10-13
|
5KB
|
172 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from ZSI import _copyright, _get_idstr, ZSI_SCHEMA_URI
from ZSI import _backtrace, _stringtypes, _seqtypes
from ZSI.wstools.Utility import MessageInterface, ElementProxy
from ZSI.wstools.Namespaces import XMLNS, SOAP, SCHEMA
from ZSI.wstools.c14n import Canonicalize
import types
_standard_ns = [
('xml', XMLNS.XML),
('xmlns', XMLNS.BASE)]
_reserved_ns = {
'SOAP-ENV': SOAP.ENV,
'SOAP-ENC': SOAP.ENC,
'ZSI': ZSI_SCHEMA_URI,
'xsd': SCHEMA.BASE,
'xsi': SCHEMA.BASE + '-instance' }
class SoapWriter:
def __init__(self, envelope = True, encodingStyle = None, header = True, nsdict = { }, outputclass = None, **kw):
if not outputclass:
pass
outputclass = ElementProxy
if not issubclass(outputclass, MessageInterface):
raise TypeError, 'outputclass must subclass MessageInterface'
self.dom = outputclass(self)
self.memo = []
self.nsdict = nsdict
self.envelope = envelope
self.encodingStyle = encodingStyle
self.header = header
self.body = None
self.callbacks = []
self.closed = False
def __str__(self):
self.close()
return str(self.dom)
def getSOAPHeader(self):
if self.header in (True, False):
return None
return self.header
def serialize_header(self, pyobj, typecode = None, **kw):
kw['unique'] = True
soap_env = _reserved_ns['SOAP-ENV']
header = self._header
if header is None:
header = self._header = self.dom.createAppendElement(soap_env, 'Header')
typecode = getattr(pyobj, 'typecode', typecode)
if typecode is None:
raise RuntimeError('typecode is required to serialize pyobj in header')
helt = typecode.serialize(header, self, pyobj, **kw)
def serialize(self, pyobj, typecode = None, root = None, header_pyobjs = (), **kw):
self.body = None
if self.envelope:
soap_env = _reserved_ns['SOAP-ENV']
self.dom.createDocument(soap_env, 'Envelope')
for prefix, nsuri in _reserved_ns.items():
self.dom.setNamespaceAttribute(prefix, nsuri)
self.writeNSdict(self.nsdict)
if self.encodingStyle:
self.dom.setAttributeNS(soap_env, 'encodingStyle', self.encodingStyle)
if self.header:
self._header = self.dom.createAppendElement(soap_env, 'Header')
for h in header_pyobjs:
self.serialize_header(h, **kw)
self.body = self.dom.createAppendElement(soap_env, 'Body')
else:
self.dom.createDocument(None, None)
if typecode is None:
typecode = pyobj.__class__.typecode
if self.body is None:
elt = typecode.serialize(self.dom, self, pyobj, **kw)
else:
elt = typecode.serialize(self.body, self, pyobj, **kw)
if root is not None:
if root not in (0, 1):
raise ValueError, 'SOAP-ENC root attribute not in [0,1]'
elt.setAttributeNS(SOAP.ENC, 'root', root)
return self
def writeNSdict(self, nsdict):
for k, v in nsdict.items():
if (k, v) in _standard_ns:
continue
rv = _reserved_ns.get(k)
if rv:
if rv != v:
raise KeyError('Reserved namespace ' + str((k, v)) + ' used')
continue
continue
if k:
self.dom.setNamespaceAttribute(k, v)
continue
self.dom.setNamespaceAttribute('xmlns', v)
def ReservedNS(self, prefix, uri):
return _reserved_ns.get(prefix, uri) != uri
def AddCallback(self, func, *arglist):
self.callbacks.append((func, arglist))
def Known(self, obj):
obj = _get_idstr(obj)
if obj in self.memo:
return 1
self.memo.append(obj)
return 0
def Forget(self, obj):
obj = _get_idstr(obj)
try:
self.memo.remove(obj)
except ValueError:
pass
def Backtrace(self, elt):
return _backtrace(elt._getNode(), self.dom._getNode())
def close(self):
if self.closed:
return None
for func, arglist in self.callbacks:
apply(func, arglist)
self.closed = True
def __del__(self):
if not self.closed:
self.close()
if __name__ == '__main__':
print _copyright